const { ccclass, property } = cc._decorator;
import { User } from "../scripts/UserManager";
import { UserData } from "../scripts/UserConst";
import { Tip } from "../scripts/TipManager";
import { Event } from "../scripts/EventManager";
import { default as GameEvent } from "../scripts/EventConst";
import crtkc from "./crtkc";
@ccclass
export default class loginReward extends cc.Component {

    @property(cc.Node)
    node_reward: cc.Node = null;


    start() {
        //@ts-ignore
        window.__prv.doAction(10, ['ks3', cc.find("content/defineBtn/AD", this.node), cc.find("content/defineBtn/icon_shipin", this.node)]);
        //@ts-ignore
        window.__prv.doAction(11, ['ks3', cc.find("content/defineBtn1", this.node)]);
    }

    /**点击奖励 */
    private clickRewardDouble() {
        let me = this;
        //@ts-ignore
        window.__prv.showVideo(function () {
            me.node_reward.active = false;
            // 增加体力值的逻辑
            let power = User.get(UserData.POWER);
            let t = 1; // 这里的t值需要根据实际情况调整
            User.set(UserData.POWER, power + 10 * t);
            Event.emit(GameEvent.POWER_EFFECT, true);

            //增加钥匙逻辑
            let key = User.get(UserData.KEY);
            User.set(UserData.KEY, key + 2);
            Event.emit(GameEvent.KEY_EFFECT, true);
            // let loginReward = crtkc.getData('loginReward', '');
            let date = new Date();
            let today = date.getUTCFullYear() + "-" + date.getUTCMonth() + "-" + date.getUTCDay();
            crtkc.saveData('loginReward', today);
            me.close()
        })
    }

    private clickReward() {
        let me = this;
        //@ts-ignore

        me.node_reward.active = false;
        // 增加体力值的逻辑
        let power = User.get(UserData.POWER);
        let t = 1; // 这里的t值需要根据实际情况调整
        User.set(UserData.POWER, power + 10 * t);
        Event.emit(GameEvent.POWER_EFFECT, true);

        //增加钥匙逻辑
        let key = User.get(UserData.KEY);
        User.set(UserData.KEY, key + 1);
        Event.emit(GameEvent.KEY_EFFECT, true);
        // let loginReward = crtkc.getData('loginReward', '');
        let date = new Date();
        let today = date.getUTCFullYear() + "-" + date.getUTCMonth() + "-" + date.getUTCDay();
        crtkc.saveData('loginReward', today);
        me.close()

    }

    private close() {
        this.node.destroy();
    }

}
